package com.twl.app.base.bo;

import static org.junit.Assert.*;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import oracle.sql.DATE;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.twl.app.base.entity.Bfsalary;
import com.twl.app.base.entity.CheckDate;
import com.twl.app.base.entity.Checktemplet;
import com.twl.app.base.entity.Jsbfmoney;
import com.twl.app.base.entity.Leavebmoney;
import com.twl.app.base.entity.Uemp;
import com.twl.app.base.util.CryptUtils;
import com.twl.app.base.util.NotNullBeanUtils;
import com.twl.core.framework.bo.impl.AbsCrudBoImpl;
import com.twl.core.framework.dao.WSHibernateDaoSupportProxy;

@Transactional
@Repository("bfBo")
public class BfBoImpl extends AbsCrudBoImpl{

	@Autowired
	private WSHibernateDaoSupportProxy wSHibernateDaoSupportProxy;
	
	public String insetBf(Bfsalary bfsalary){
		try {
			String hql = "from Bfsalary where staffint='"+bfsalary.getStaffint()+"' and Datemoney='"+bfsalary.getDatemoney()+"'";
			List<Bfsalary> listBF = super.findAll(hql);
			//解密
			List<Bfsalary> list = CryptUtils.decrypt(listBF);
			if(list.size()>0){
				//bfsalary.setDid(list.get(0).getDid());
				NotNullBeanUtils.copyProperties(list.get(0),bfsalary);
				wSHibernateDaoSupportProxy.saveOrUpdate(list.get(0));

			}else{
				wSHibernateDaoSupportProxy.saveOrUpdate(bfsalary);

			}
		} catch (Exception e) {
			e.printStackTrace();
			return "fail";
		}
		return "ok";
	}
	
	public String insertJsbf(Jsbfmoney jsbfmoney){
		
		try {
			String hql = "from Jsbfmoney where staffint='"+jsbfmoney.getStaffint()+"' and Datemoney='"+jsbfmoney.getDatemoney()+"'";
			List<Jsbfmoney> listJSBF = super.findAll(hql);
			
			//解密
			List<Jsbfmoney> list = CryptUtils.decrypt(listJSBF);
			//Jsbfmoney jsbf =  CryptUtils.encrypt(jsbfmoney);

			if(list.size()>0){
				//jsbfmoney.setDid(list.get(0).getDid());
				NotNullBeanUtils.copyProperties(list.get(0),jsbfmoney);
				wSHibernateDaoSupportProxy.saveOrUpdate(list.get(0));

			}else{
				wSHibernateDaoSupportProxy.saveOrUpdate(jsbfmoney);

			}
		} catch (Exception e) {
			e.printStackTrace();
			return "fail";
		}
			return "ok" ;
		}
	
	@Deprecated	
	public String updateUempByBf(Uemp uemp){
		try {
			super.updateData(uemp);
		} catch (Exception e) {
			e.printStackTrace();
			return "false" ;
		}
		return "ok" ;
	}
	
	@Deprecated
	public Bfsalary queryBF(String staffint){
		String hql = "from Bfsalary where staffint='"+staffint+"' order by did";
		List<Bfsalary> list = super.findAll(hql);
		if(list.size()>0){
			return list.get(0);
		}else{
			return null ;
		}
	}
	@Deprecated
	public Jsbfmoney queryJSBF(String staffint){
		String hql = "from Jsbfmoney where staffint='"+staffint+"' order by did";
		List<Jsbfmoney> list = super.findAll(hql);
		if(list.size()>0){
			return list.get(0);
		}else{
			return null ;
		}
	}
}
